package cn.tedu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class testjdbc1 {
    public static void main(String[] args) throws Exception {
        method();
    }

    private static void method() throws Exception {
        //1.注册驱动jar包
        Class.forName("com.mysql.jdbc.Driver");
        //2.连接数据库
        Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctest","root","root");
        //3.获取传输器
        Statement st=con.createStatement();
        //4.执行sql
        String sql ="select * from user where name='jack' and pwd='123'";
        ResultSet rs=st.executeQuery(sql);
        //5.解析结果集
        while (rs.next()){
            String id=rs.getString(1);
            String name=rs.getString(2);
            String pwd=rs.getString(3);
            System.out.println(id+name+pwd);
        }
        //6.释放资源
        rs.close();
        st.close();
        con.close();
    }
}
